package cn.itcast.zt.hystrix;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * create by zhangtian on 2018/4/12
 */
@Slf4j
@RestController
@RequestMapping(value = "hystrix1")
@DefaultProperties(defaultFallback = "defaultFail")
public class HystrixController1 {

    @HystrixCommand(fallbackMethod = "fail1")
    @GetMapping(value = "test1")
    public String test1(){
        throw new RuntimeException() ;
    }

    private String fail1() {
        log.warn("fail1");
        return "fail1";
    }

    @HystrixCommand(fallbackMethod = "fail2")
    @GetMapping(value = "test2")
    public String test2() {
        throw new RuntimeException();
    }

    @HystrixCommand(fallbackMethod = "fail3")
    private String fail2() {
        log.warn("fail2");
        throw new RuntimeException();
    }

    @HystrixCommand
    private String fail3() {
        log.warn("fail3");
        throw new RuntimeException();
    }

    private String defaultFail() {
        log.warn("default fail");
        return "default fail";
    }
}
